package hsintiao.com.xintiaoAPP.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.text.SimpleDateFormat;
import java.util.Date;

public class EmailUtil {

    private String path = "E:\\bill";
    //private String path = "/yft/myProject/xtyl/paybill/";
    @Autowired
    private JavaMailSender mailSender;

    //没有问题时发送的账单邮件
    public void allOKBillMail(Date date){
        date.setTime(date.getTime()-1000*60*60*24);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String time = format.format(date);
        System.out.println("日期="+time);
        System.out.println("日期="+date);
        MimeMessage message = mailSender.createMimeMessage();
        try {
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setFrom("931409313@qq.com");
            helper.setTo("1730592409@qq.com");
            helper.setSubject(time+"的账单");
            helper.setText("该日支付宝账单没有问题，携带该日支付宝账单文件");
            FileSystemResource file = new FileSystemResource(path+time+".zip");
            helper.addAttachment(time+".zip",file);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
        mailSender.send(message);
    }




}
